<template>
	<view class="page-content">
		<u-list v-if="hasAct" @scrolltolower="listScrollTolower" :customStyle="{
			marginBottom: '100rpx',paddingTop: '20rpx'
			}">
			<view v-if="dataList.bank.length">
				<view class="cardtitle c_999999">
					<text class="c_000000">我的卡</text>（共{{dataList.bank.length||0}}张）
				</view>
				<view class="bg_fff pd-20 actItemBox mt-20" v-for="(item, index) in dataList.bank" :key="index"
					@click="goPage(item.id,item.type)">
					<view class="itemBaseBox">
						<u-image
							src="https://dtkj-qnyimg.diankuai.com/%E6%94%B6%E7%9B%8A/48%E9%93%B6%E8%A1%8C%E5%8D%A1.png"
							width="130rpx" height="130rpx">
						</u-image>
						<view class="itemBase f_28">
							<text class="c_333333 title">{{subAccount(item.account)}}</text>
							<view>
								<text class="c_999999 f-24">{{item.bankInfo.name}}</text>
								<text class="c_999999 f-24"
									style="margin-left: 40rpx;">开户名：{{subName(item.name)}}</text>
							</view>
						</view>
					</view>
					<u-icon name="arrow-right" size="16"></u-icon>
				</view>
			</view>
			<view v-if="dataList.wechat.length">
				<view class="cardtitle c_999999">
					<text class="c_000000">微信</text>（共{{dataList.wechat.length||0}}个）
				</view>
				<view class="bg_fff pd-20 actItemBox mt-20" v-for="(item, index) in dataList.wechat" :key="index"
					@click="goPage(item.id,item.type)">
					<view class="itemBaseBox">
						<u-image
							src="https://dtkj-qnyimg.diankuai.com/%E6%94%B6%E7%9B%8A/%E5%BE%AE%E4%BF%A1%E6%94%AF%E4%BB%98.png"
							width="130rpx" height="130rpx">
						</u-image>
						<view class="itemBase f_28">
							<text class="c_333333 title">{{item.account}}</text>
							<view>
								<text class="c_999999 f-24">{{subPhone(item.phone)}}</text>
								<text class="c_999999 f-24" style="margin-left: 40rpx;">姓名：{{subName(item.name)}}</text>
							</view>
						</view>
					</view>
					<u-icon name="arrow-right" size="16"></u-icon>
				</view>
			</view>
			<view v-if="dataList.ali.length">
				<view class="cardtitle c_999999">
					<text class="c_000000">支付宝</text>（共{{dataList.ali.length||0}}个）
				</view>
				<view class="bg_fff pd-20 actItemBox mt-20" v-for="(item, index) in dataList.ali" :key="index"
					@click="goPage(item.id,item.type)">
					<view class="itemBaseBox">
						<u-image
							src="https://dtkj-qnyimg.diankuai.com/%E6%94%B6%E7%9B%8A/%E6%94%AF%E4%BB%98%E5%AE%9D.png"
							width="130rpx" height="130rpx">
						</u-image>
						<view class="itemBase f_28">
							<text class="c_333333 title">{{item.account}}</text>
							<view>
								<text class="c_999999 f-24">{{subPhone(item.phone)}}</text>
								<text class="c_999999 f-24" style="margin-left: 40rpx;">姓名：{{subName(item.name)}}</text>
							</view>
						</view>
					</view>
					<u-icon name="arrow-right" size="16"></u-icon>
				</view>
			</view>
		</u-list>
		<u-empty mode="list" v-else :customStyle="{flex:'1'}"></u-empty>

		<view class="btmBox c_ffffff" @click="showSheet">
			添加账户
		</view>

		<u-action-sheet :show="show2" @close="closeSheet" :actions="actions2" cancelText="取消" @select="goNext">
		</u-action-sheet>
	</view>
</template>

<script>
	import {
		getCashAccount
	} from '@/config/api.js'

	export default {
		data() {
			return {
				actions2: [{
						type: 1,
						name: '微信',
					},
					{
						type: 2,
						name: '支付宝',
					},
					{
						type: 3,
						name: '银行卡',
					},
				],
				show2: false,
				hasAct: true,
				dataList: null
			}
		},
		onShow() {
			this.getData();
		},
		methods: {
			goPage(id, type) {
				uni.navigateTo({
					url: "/pages/center/addCashAccount?id=" + id + "&type=" + type
				})
			},
			subName(name) {
				var nameLen = name.length;
				var end = name.substr(-(nameLen - 1));
				return "*" + end;
			},
			subPhone(phone) {
				var start = phone.substr(0, 3);
				var end = phone.substr(-4);
				return start + "****" + end;
			},
			subAccount(account) {
				var start = account.substr(0, 4);
				var end = account.substr(-4);
				return start + "*********" + end;
			},
			goNext(e) {
				this.closeSheet();
				uni.navigateTo({
					url: "/pages/center/addCashAccount?type=" + e.type
				})
			},
			showSheet() {
				this.show2 = true;
			},
			closeSheet() {
				this.show2 = false;
			},
			getData() {
				getCashAccount().then(res => {
					this.dataList = res;
					if (res.wechat.length > 0 || res.ali.length > 0 || res.bank.length > 0) {
						this.hasAct = true;
					}
				})
			}
		}
	}
</script>

<style scoped>
	.btmBox {
		background: linear-gradient(to bottom, #C62B2C, #FF7C71);
		border-radius: 40rpx;
		line-height: 80rpx;
		text-align: center;
		font-size: 40rpx;
		font-weight: 600;
		box-sizing: border-box;
		margin-left: 5%;
		width: 90%;
		position: fixed;
		bottom: 20rpx;
	}

	.actItemBox {
		width: 90%;
		margin-left: 5%;
		border-radius: 20rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: row;
	}

	.itemBaseBox {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		flex: 9;
	}

	.itemBase {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: flex-start;
		margin-left: 20rpx;
		flex: 2;
		height: 130rpx;
	}

	.cardtitle {
		width: 90%;
		box-sizing: border-box;
		margin-left: 5%;
		margin-top: 40rpx;
	}
</style>
